#Author:Math2Gold ( http://groups.google.com/group/math2gold ) 
#Last update:2009 Sep 11

from google.appengine.api import xmpp
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
import default_m2g_conf
import m2g_misc

class XMPPHandler(webapp.RequestHandler):
	def post(self):		
		message = xmpp.Message(self.request.POST)
		m=self.request.get('from')
		if m[0:len(default_m2g_conf.user_gtalk)+1].lower() ==default_m2g_conf.user_gtalk+'/' :
			m2g_misc.sendMBlog(message.body.encode("UTF-8"),
							   default_m2g_conf.twitter_username,
							   default_m2g_conf.twitter_password,
					  uri=default_m2g_conf.twitter_senduri,
					  prefix='status=')
			message.reply("ok,sent!")
		else:
			message.reply("you're"+self.request.get('from'))

application = webapp.WSGIApplication([('/_ah/xmpp/message/chat/', XMPPHandler)],
                                     debug=False)

def main():
  run_wsgi_app(application)

if __name__ == "__main__":
  main()
